/**
*  \file  dp_fft_ifft_support_module.c
*/


#include <math.h>

/* generate real and imaginary twiddle table of size n/2 complex numbers */
void gen_w_r2(double* w, int n)
{
	int i;
	double pi = 4.0 * atan(1.0);
	double e = pi * 2.0 / n;

	for (i = 0; i < (n >> 1); i++)
	{
		w[2 * i] = cos(i * e);
		w[2 * i + 1] = sin(i * e);
	}
}

/* bit reverse coefficients */
void bit_rev(double* x, int n)
{
	int i, j, k;
	double rtemp, itemp;
	j = 0;

	for (i = 1; i < (n - 1); i++)
	{
		k = n >> 1;

		while (k <= j)
		{
			j -= k;
			k >>= 1;
		}

		j += k;

		if (i < j)
		{
			rtemp = x[j * 2];
			x[j * 2] = x[i * 2];
			x[i * 2] = rtemp;
			itemp = x[j * 2 + 1];
			x[j * 2 + 1] = x[i * 2 + 1];
			x[i * 2 + 1] = itemp;
		}
	}
}


